<template>
    <div style="width: 300px;">

        <Form ref="organizeInfo" :model="organizeInfo" :rules="ruleOrganizeInfo">
            <FormItem prop="orgId">
                <Input type="text" v-model="organizeInfo.orgId" placeholder="机构代码">
                <Icon type="ios-person-outline" slot="prepend"></Icon>
                </Input>
            </FormItem>
            <FormItem prop="orgName">
                <Input type="text" v-model="organizeInfo.orgName" placeholder="机构名称">
                <Icon type="ios-person-outline" slot="prepend"></Icon>
                </Input>
            </FormItem>
            <FormItem prop="orgParentId">
                <Input type="text" v-model="organizeInfo.orgParentId" placeholder="机构父级代码" readonly="">
                <Icon type="ios-person-outline" slot="prepend"></Icon>
                </Input>
            </FormItem>

            <!--  <FormItem >
                  <i-switch v-model="organizeInfo.isAvailable" size="large">
                      <span slot="open">开启</span>
                      <span slot="close">关闭</span>
                  </i-switch>
              </FormItem>-->

        </Form>

    </div>
</template>

<script>
    export default {
        name: "OrganizeInfo",
        data() {
            return {
                organizeInfo: {
                    orgId: '',
                    orgName: '',
                    orgParentId: '',
                    //  isAvailable: true
                },
                ruleOrganizeInfo: {
                    orgId: [
                        {required: true, message: '请填写机构代码', trigger: 'blur'}
                    ],
                    orgName: [
                        {required: true, message: '请填写机构名称', trigger: 'blur'}
                    ],
                    orgParentId: [
                        {required: true, message: '请填写父级机构代码', trigger: 'blur'}
                    ],
                }

            };
        },
        props: ['orgParentId'],
        methods: {
            /*change(status) {
                this.$Message.info('开关状态：' + status);
            }*/
            resetOrganizeInfo() {
                let self = this;
                self.$refs['organizeInfo'].resetFields();
            },
            saveOrganizeInfo() {
                let self = this;
                this.$http({
                    headers: {'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'},
                    transformRequest: [data => self.$qs.stringify(data)],
                    method: 'post',
                    url: '/core/organizeInfo/addOrgnizeInfo',
                    data: {
                        orgId: self.organizeInfo.orgId,
                        orgName: self.organizeInfo.orgName,
                        orgParentId: self.organizeInfo.orgParentId
                    }
                }).then(function (response) {
                    self.common.handleData(response.data, self);
                    self.$emit('listenToChildEvent', self.organizeInfo.orgParentId);
                    self.resetOrganizeInfo();

                }).catch(function (error) {
                    console.log(error);
                });
            }

        }

    }
</script>

<style scoped>

</style>